import qqmap from '../../../utils/qq.map'
Page({
  data: {
    // latitude: 40.060539,
    // longitude: 116.343847,
    latitude: '',
    longitude: '',
    locationName: '中国广州吉山幼儿园',
    // 报修详情
    repairInfo: null,
  },
  onLoad({ id }) {

    this.getRepairInfo(id)
    this.geocoder(this.data.locationName)
  },
  // 根据id来查询报修详情
  async getRepairInfo(id) {
    const res = await wx.http({ url: `/repair/${id}` })
    console.log(res)
    this.setData({
      repairInfo: res.data,
    })
  },

  // 根据地理位置描述获取经纬度
  geocoder(address) {
    qqmap.geocoder({
      address,
      success: (res) => {
        // console.log(res)
        const latitude = res.result.location.lat
        const longitude = res.result.location.lng
        this.setData({ latitude, longitude })
      },
    })
  },
  // 跳转到from
  onGoform() {
    wx.navigateTo({ url: '/repair_pkg/pages/form/index?id=' + this.data.repairInfo.id, })

  },
  // 取消保修
  onChange() {
    // console.log(1);
    wx.showModal({
      title: '提示',
      content: '确定要删除吗',
      success: async ({ confirm }) => {
        if (confirm) {
          const res = await wx.http({ url: `/cancel/repaire/${this.data.repairInfo.id}`, method: 'put' })
          // console.log(res);
          if (res.code === 10000) {
            return wx.showToast(res.message)
          }

          wx.showToast({
            title: '提示'
          })
          setTimeout(() => {
            wx.navigateTo({
              url: '/repair_pkg/pages/list/index'
            })
          }, 1500)
        }
      }
    })
  }
})